﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MISAPP.Classify.Service;

    
public partial class View_WMG_WMG008 : ViewMatrix
{
    string excelFile = "WMG外幣利差設算.xls";
    protected void Page_Load(object sender, EventArgs e)
    {        
        Title = "財管外幣利差試算";
        criteriaList = new string[] { "Year" };
        serviceName = "MISAPP.Classify.Service.Service_CIB_DD_TD";
        if (!IsPostBack)
        {
            txtYear.Text = DateTime.Now.Year.ToString();
        }

    }
    protected void btn_Execute_Click(object sender, EventArgs e)
    {
        execute();
    }

    protected void btn_ExexYM_Click(object sender, EventArgs e)
    {
        execute("");
    }

    protected void execute()
    {
        string dlFile = Utility.TemplateToDownload(
            Server.MapPath("~"), excelFile, "xls");

        string year = txtYear.Text.Length == 0 ?
             DateTime.Now.Year.ToString() : txtYear.Text;
        MISAPP.Classify.Service.Service_CIB_DD_TD ddtd =
            new MISAPP.Classify.Service.Service_CIB_DD_TD();

        Squared_Excel seq_xls = new Squared_Excel();
        //seq_xls.GetWMG_DDTD(ddtd, dlFile, year);
        seq_xls.GetCIB_DDTD(ddtd, dlFile, year, "GetWMGSummaryData");
        linkExcel.NavigateUrl = string.Format("~/download/{0}",
           System.IO.Path.GetFileName(dlFile));
        linkExcel.Text = "結果";
        seq_xls.ReleaseExcel();

    }

    protected void execute(string p)
    {
        if (!verify())
        { return; }
        string dlFile = Utility.TemplateToDownload(
            Server.MapPath("~"), excelFile, "xls");

        string year = txtYear.Text.Length == 0 ?
             DateTime.Now.Year.ToString() : txtYear.Text;


        MISAPP.Classify.Service.Service_CIB_DD_TD ddtd =
            new MISAPP.Classify.Service.Service_CIB_DD_TD();
        string[] yms = { txtYM1.Text, txtYM2.Text };
        Squared_Excel seq_xls = new Squared_Excel();
        seq_xls.GetCIB_DDTD(ddtd, dlFile, yms, "GetWMGSummaryData");
        linkExcel.NavigateUrl = string.Format("~/download/{0}",
           System.IO.Path.GetFileName(dlFile));
        linkExcel.Text = "結果";
        seq_xls.ReleaseExcel();
    }

    protected bool verify()
    {
        bool ok = true;
        if (string.IsNullOrEmpty(txtYM1.Text))
        {
            ok = false;
            lblResult.Text = "請輸入開始年月YYYYMM";
        }
        if (string.IsNullOrEmpty(txtYM2.Text))
        {
            ok = false;
            lblResult.Text = "請輸入結束年月YYYYMM";
        }
        return ok;
    }
}
